package com.ucode.model.hrm.convert;

import cn.hutool.core.util.StrUtil;
import com.ucode.model.hrm.*;
import com.ucode.model.hrm.enums.HrmEmployeeContractStatusEnum;
import com.ucode.model.hrm.enums.HrmEmployeeContractTypeEnum;
import com.ucode.model.hrm.form.HrmEmployeeContractRenewForm;
import com.ucode.model.hrm.vo.HrmEmployeeContractSimpleVO;
import com.ucode.model.hrm.vo.HrmEmployeeContractVO;
import com.ucode.tool.base.Paginator;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface HrmEmployeeContractConvert {

    HrmEmployeeContractConvert INSTANCE = Mappers.getMapper(HrmEmployeeContractConvert.class);

    //HrmEmployeeContract convert(HrmCustomerProjectForm form);

    HrmEmployeeContractVO convert(HrmEmployeeContract bean);

    Paginator<HrmEmployeeContractVO> convertPage(Paginator<HrmEmployeeContract> page);

    List<HrmEmployeeContractSimpleVO> convertSimpleList(List<HrmEmployeeContract> list);
    default HrmEmployeeContract build(HrmEmployee employee, HrmEmployeeCompensation compensation, HrmCompany company, HrmContractTpl contractTpl) {
        HrmEmployeeContract bean = new HrmEmployeeContract();
        bean.setEmployeeId(employee.getId());
        bean.setEmployeeName(employee.getRealName());
        bean.setEmployeeMobile(employee.getPhone());
        bean.setEmployeeIdCard(employee.getIdCardNumber());
        bean.setEmployeeAddress(StrUtil.isNotBlank(employee.getDetailedAddress()) ? employee.getDetailedAddress() : employee.getResidentialAddress());
        bean.setEmployeeMobile2(StrUtil.isNotBlank(employee.getCnontactPhone()) ? employee.getCnontactPhone() : employee.getCnontactPhone1());
        bean.setEmployeeEmail(employee.getEmail());
        bean.setBaseSalary(compensation.getBaseSalary());
        bean.setPaySalaryDay(compensation.getPaySalaryDay());

        bean.setCustomCompany(employee.getCustomCompany());
        bean.setDeptName(employee.getDepartmentName());
        bean.setJobName(employee.getPositionName());
        bean.setWorkLocation(employee.getWorkLocation());

        bean.setCustomerCompanyId(employee.getCompanyId());
        bean.setCustomerProjectId(employee.getProjectId());

        bean.setTemplateId(contractTpl.getId());
        bean.setName(employee.getRealName()+ (StrUtil.isNotBlank(contractTpl.getContentName()) ? "_"+contractTpl.getContentName() : "_劳动合同"));


        bean.setSignCompanyId(company.getId());
        bean.setThreeStorageId(company.getThreeStorageId());
        bean.setSignCompanyName(company.getName());
        bean.setSignCompanyAddress(company.getRegAddress());
        bean.setSignCompanyEmail(company.getEmail());

        bean.setStartDate(employee.getHireDate());
        bean.setEndDate(employee.getContractEndDate());
        bean.setTrialEndDate(employee.getTrialEndDate());
        bean.setStatus(HrmEmployeeContractStatusEnum.EMPLOYEE_PENDING.getCode());
        bean.setContractType(HrmEmployeeContractTypeEnum.FIRST.getCode());

        return bean;
    }

    /**
     * 构建续签合同
     * @param employee
     * @param compensation
     * @param employeeContract
     * @param company
     * @param contractTpl
     * @param form
     * @return
     */
    default HrmEmployeeContract buildRenew(HrmEmployee employee, HrmEmployeeCompensation compensation,HrmEmployeeContract employeeContract,HrmCompany company, HrmContractTpl contractTpl, HrmEmployeeContractRenewForm form){
        HrmEmployeeContract bean = new HrmEmployeeContract();
        bean.setEmployeeId(employeeContract.getEmployeeId());
        bean.setEmployeeName(employee.getRealName());
        bean.setEmployeeMobile(employee.getPhone());
        bean.setEmployeeIdCard(employee.getIdCardNumber());
        bean.setEmployeeAddress(employee.getResidentialAddress());
        bean.setEmployeeMobile2(StrUtil.isNotBlank(employee.getCnontactPhone()) ? employee.getCnontactPhone() : employee.getCnontactPhone1());
        bean.setEmployeeEmail(employee.getEmail());
        bean.setBaseSalary(compensation.getBaseSalary());
        bean.setPaySalaryDay(compensation.getPaySalaryDay());

        bean.setCustomCompany(employee.getCustomCompany());
        bean.setDeptName(employee.getDepartmentName());
        bean.setJobName(employee.getPositionName());
        bean.setWorkLocation(employee.getWorkLocation());

        bean.setCustomerCompanyId(employee.getCompanyId());
        bean.setCustomerProjectId(employee.getProjectId());

        bean.setTemplateId(contractTpl.getId());
        bean.setName(employee.getRealName()+ (StrUtil.isNotBlank(contractTpl.getContentName()) ? "_"+contractTpl.getContentName() : "_劳动合同"));
        bean.setPaySalaryDay(contractTpl.getThreeTemplateId());

        bean.setSignCompanyId(company.getId());
        bean.setThreeStorageId(company.getThreeStorageId());
        bean.setSignCompanyName(company.getName());
        bean.setSignCompanyAddress(company.getRegAddress());
        bean.setSignCompanyEmail(company.getEmail());

        bean.setStartDate(employeeContract.getEndDate());
        bean.setEndDate(form.getEndDate());
        bean.setTrialEndDate(null);
        bean.setStatus(HrmEmployeeContractStatusEnum.EMPLOYEE_PENDING.getCode());
        bean.setContractType(HrmEmployeeContractTypeEnum.CONTINUE.getCode());

        return bean;
    }

}


